package com.gsit.expenditure.services;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.gsit.expenditure.domain.Item;
import com.gsit.expenditure.domain.Order;
import com.gsit.expenditure.utils.AppContextLoader;

@Repository
public class OrderService {

	@PersistenceContext
	private EntityManager entityManager;
	

	@Transactional
	public void addDummyOrder(final String customer) {
		Order order = new Order();
		Item item = new Item();
		item.setPrice(200.00);
		item.setProduct("FIR");
		item.setQuantity(10);
		order.getItems().add(new Item());
		order.setCustomer(customer);
		entityManager.persist(order);
		entityManager.flush();
	}
	
	
	@Transactional
	public List<Order> findAllOrder() {
		return entityManager.createQuery("select order from Order order", Order.class).getResultList();
		
	}

}
